package com.ashin.springmvc;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class MainController {

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String listTutorialsPage(Model model) {

        Tutorial t1 = new Tutorial();
        t1.setTutId(1L);
        t1.setAuthor("Ashin");
        t1.setTitle("spring mvc velocity");
        t1.setDescription("velocity tutorial");

        List<Tutorial> list = new ArrayList<>();
        list.add(t1);

        model.addAttribute("tutorials", list);

        return "main";
    }

    public static class Tutorial {

        private Long tutId;
        private String title;
        private String description;
        private String author;

        public Long getTutId() {
            return tutId;
        }

        public void setTutId(Long tutId) {
            this.tutId = tutId;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getAuthor() {
            return author;
        }

        public void setAuthor(String author) {
            this.author = author;
        }

    }
}